import Vue from 'vue'
import Router from 'vue-router'
import store from '../vuex/user'
import Index from '@/view/main/Index'
import Main from '@/view/Main'
import  { ConfirmPlugin } from 'vux'
Vue.use(ConfirmPlugin)
Vue.use(Router)
const { service_id } = store.state.userInfo

const NotFoundComponent = resolve => require(['../view/404.vue'], resolve) //404
const BindSuccess = resolve => require(['../view/BindSuccess.vue'], resolve) //404
const Login = resolve => require(['../view/Login.vue'], resolve) //注册
const BindUser = resolve => require(['../view/BindUser.vue'], resolve) //第三方登录绑定手机号码
const CodeLogin = resolve => require(['../view/CodeLogin.vue'], resolve) //验证码登录
const Logout = resolve => require(['../view/Logout.vue'], resolve) //退出登录
const Recharge = resolve => require(['../view/Recharge.vue'], resolve) //充值
const Reg = resolve => require(['../view/Reg.vue'], resolve) // 注册
const FindPwd = resolve => require(['../view/FindPwd.vue'], resolve) //找回密码
const SetPayPwd = resolve => require(['../view/SetPayPwd.vue'], resolve) //设置交易密码
const Setting = resolve => require(['../view/Setting.vue'], resolve) // 系统设置
const Help = resolve => require(['../view/Help.vue'], resolve) // 帮助中心
const HelpArticle = resolve => require(['../view/HelpArticle.vue'], resolve) //文章
const Account = resolve => require(['../view/Account.vue'], resolve) // 我的账户
const Withdrawals = resolve => require(['../view/Withdrawals.vue'], resolve) //提现
const AddWithdrawals = resolve => require(['../view/AddWithdrawals.vue'], resolve) //添加提现
const Commission = resolve => require(['../view/Commission.vue'], resolve) //我的佣金
const WaitingInquiry = resolve => require(['../view/WaitingInquiry.vue'], resolve) // 等待询价界面
const User = resolve => require(['../view/User.vue'], resolve) // 我的主页
const DriverPage = resolve => require(['../view/DriverPage.vue'], resolve) // 我的主页
const OrderConfirm = resolve => require(['../view/OrderConfirm.vue'], resolve) // 同城专车，零担专线，整车下单后运单确认
const InDispatch = resolve => require(['../view/InDispatch.vue'], resolve) // 同城专车，零担专线，整车运单详情
const InDispatch2 = resolve => require(['../view/InDispatch2.vue'], resolve) // 同城专车，零担专线，整车运单详情
const ExpressInDispatch = resolve => require(['../view/ExpressInDispatch.vue'], resolve) // 快递宝订单详情
const ExpressInquiry = resolve => require(['../view/ExpressInquiry.vue'], resolve) // 快递查询

const Comment = resolve => require(['../view/Comment.vue'], resolve) // 评论
const Complaint = resolve => require(['../view/Complaint.vue'], resolve) // 投诉
//user
const PersonallyIdentifying = resolve => require(['../view/user/PersonallyIdentifying.vue'], resolve) //个人认证表单
const CompanyIdentifying = resolve => require(['../view/user/CompanyIdentifying.vue'], resolve) //个人认证表单
const SelectAuthentication = resolve => require(['../view/user/SelectAuthentication.vue'], resolve) //选择认证方式(企业、个人)
const InAudit = resolve => require(['../view/user/InAudit.vue'], resolve) //审核中
const AuditSuccess = resolve => require(['../view/user/AuditSuccess.vue'], resolve) //个人认证成功
const SetNickName = resolve => require(['../view/user/SetNickName.vue'], resolve) //修改昵称
const Credits = resolve => require(['../view/user/Credits.vue'], resolve) // 信誉值详情
const CreditsList = resolve => require(['../view/user/CreditsList.vue'], resolve) // 信誉值详情

const ToCollection = resolve => require(['@/view/toCollection.vue'], resolve) //日账单
//账单
const AccountListDay = resolve => require(['@/view/AccountListDay.vue'], resolve) //日账单
const AccountList = resolve => require(['@/view/AccountList.vue'], resolve) //月年账单
const CommissionList = resolve => require(['@/view/CommissionList.vue'], resolve) //佣金明细
//分享
const ShareTn = resolve => require(['@/view/ShareTn.vue'], resolve) // 分享有礼
//运力
//调度我的司机
const DispatchDriver = resolve => require(['@/view/DispatchDriver.vue'], resolve) //佣金明细
const UserPage = resolve => require(['@/view/UserPage.vue'], resolve) //佣金明细
const SelectService = resolve => require(['@/view/SelectService.vue'], resolve) //选择业务类型
const Warning = resolve => require(['@/view/Warning.vue'], resolve) //错误页面
const Offer = resolve => require(['@/view/Offer.vue'], resolve) //报价
const ReportDriver = resolve => require(['@/view/ReportDriver.vue'], resolve) //上报司机
const PayOfInformation = resolve => require(['@/view/PayOfInformation.vue'], resolve) //支付信息费
export default new Router({
	base: __dirname,
	mode: 'hash',
  routes: [{
    path: '/',
    redirect: 'index',
    component: Main,
    meta: { requiresAuth: true },
    children: [{
        path: 'index',
        name: 'index',
        component: Index,
        meta: { requiresAuth: true, title: '待报价' }
    }, {
      path: 'bid',
      component: resolve => require(['@/view/main/Bid.vue'], resolve),
      meta: { requiresAuth: true, title: '已中标'},
    }, {
      path: 'bid2',
      component: resolve => require(['@/view/main/Bid.vue'], resolve),
      meta: { requiresAuth: true, title: '已报价'},
    }, {
      path: 'order',
      component: resolve => require(['@/view/main/Order.vue'], resolve),
      meta: { requiresAuth: true, title: '我的运单' }
    }, {
      path: 'driver',
      component: resolve => require(['@/view/main/Driver.vue'], resolve),
      meta: { requiresAuth: true, title: '我的车队' }
    }, {
      path: 'userPage',
      component: UserPage,
      meta: { requiresAuth: true }
    }]
  }, {
    path: '/login',
    name: 'login',
    component: Login,
    meta: { title: '登录' },
  }, {
    path: '/bindUser',
    name: 'bindUser',
    component: BindUser,
    meta: { title: '绑定手机' },
  }, {
    path: '/bindSuccess',
    name: 'bindSuccess',
    component: BindSuccess,
    meta: { title: '绑定成功' },
  }, {
    path: '/codeLogin',
    name: 'codeLogin',
    component: CodeLogin,
    meta: { title: '验证码登录' },
  }, {
    path: '/reg',
    name: 'reg',
    component: Reg,
    meta: { title: '注册' },
  }, {
    path: '/help',
    name: 'help',
    component: Help,
    meta: { title: '帮助中心' },
  }, {
    path: '/helpArticle',
    name: 'helpArticle',
    component: HelpArticle,
    meta: { title: '帮助中心' },
  }, {
    path: '/findPwd',
    name: 'findPwd',
    meta: { title: '重置登录密码' },
    component: FindPwd
  }, {
    path: '/setPayPwd',
    name: 'setPayPwd',
    meta: { title: '设置交易密码' },
    component: SetPayPwd
  }, {
    path: '/comment',
    name: 'comment',
    component: Comment,
    meta: { requiresAuth: true, title: '评价' }
  }, {
    path: '/complaint',
    name: 'complaint',
    component: Complaint,
    meta: { requiresAuth: true, title: '投诉' }
  }, {
    path: '/account',
    name: 'account',
    component: Account,
    meta: { requiresAuth: true, title: '我的账户' }
  }, {
    path: '/setting',
    name: 'setting',
    component: Setting,
    meta: { requiresAuth: true, title: '设置' }
  }, {
    path: '/recharge',
    name: 'recharge',
    component: Recharge,
    meta: { requiresAuth: true, title: '充值' }
  }, {
    path: '/withdrawals',
    name: 'withdrawals',
    component: Withdrawals,
    meta: { requiresAuth: true, title: '提现' },
    beforeEnter(to, from, next) {
      const { verify_company, verify_card } = store.state.userInfo
      if(verify_company != 1 && verify_card != 1) {
        Vue.$vux.confirm.show({
          title: '<i class="icon icon-gantanhao"></i>',
          content: '为保障您的合法权益，请先进行认证后才能使用提现功能！',
          confirmText: '去认证',
          cancelText: '取消',
          onConfirm: () => {
            next({ path: '/user/selectAuthentication' })
          }
        })
      } else {
        next()
      }
    }
  }, {
    path: '/logout',
    name: 'logout',
    component: Logout
  }, {
    path: '/addwithdrawals',
    name: 'addwithdrawals',
    component: AddWithdrawals,
    meta: { requiresAuth: true, title: '添加提现账户'  }
  }, {
    path: '/commission',
    name: 'commission',
    component: Commission,
    meta: { requiresAuth: true, title: '我的佣金' }
  }, {
    path: '/waitingInquiry',
    name: 'waitingInquiry',
    component: WaitingInquiry,
    meta: { requiresAuth: true }
  }, {
    path: '/inDispatch',
    name: 'inDispatch',
    component: InDispatch,
    meta: { requiresAuth: true, title: '运单详情' },
  }, {
    path: '/inDispatch2',
    name: 'inDispatch2',
    component: InDispatch2,
    meta: { requiresAuth: true, title: '运单详情' },
  }, {
    path: '/expressInDispatch',
    name: 'expressInDispatch',
    component: ExpressInDispatch,
    meta: { requiresAuth: true, title: '运单详情' },
  }, {
    path: '/expressInquiry',
    name: 'expressInquiry',
    component: ExpressInquiry,
    meta: { requiresAuth: true, title: '查询结果' },
  }, {
    path: '/orderConfirm',
    name: 'orderConfirm',
    component: OrderConfirm,
    meta: { requiresAuth: true, title: '运单确认' },
  }, {
    path: '/user',
    name: 'user',
    component: User,
    meta: { requiresAuth: true, title: '我的主页' },
  }, {
    path: '/user/personallyIdentifying',
    name: 'personallyIdentifying',
    component: PersonallyIdentifying,
    meta: { requiresAuth: true, title: '身份认证' },
    beforeEnter(to, from, next) {
      const { verify_company, verify_card } = store.state.userInfo
      if(verify_card == 3 || verify_card == 1 || verify_company == 1 || verify_company == 3) {
        next({ path: '/user' })
      } else {
        next()
      }
    }
  }, {
    path: '/user/companyIdentifying',
    name: 'companyIdentifying',
    component: CompanyIdentifying,
    meta: { requiresAuth: true, title: '企业信息' },
    beforeEnter(to, from, next) {
      const { verify_company, verify_card } = store.state.userInfo
      if(verify_company == 1 || verify_company == 3) {
        next({ path: '/user' })
      } else {
        next()
      }
    }
  }, {
    path: '/user/selectAuthentication',
    name: 'selectAuthentication',
    component: SelectAuthentication,
    meta: { requiresAuth: true, title: '选择身份认证' }
  }, {
    path: '/user/credits',
    name: 'credits',
    component: Credits,
    meta: { requiresAuth: true, title: '信用值' }
  }, {
    path: '/user/creditsList',
    name: 'creditsList',
    component: CreditsList,
    meta: { requiresAuth: true, title: '扣分记录' }
  }, {
    path: '/user/auditSuccess',
    name: 'auditSuccess',
    component: AuditSuccess,
    meta: { requiresAuth: true, title: '认证' }
  }, {
    path: '/user/setNickName',
    name: 'setNickName',
    component: SetNickName,
    meta: { requiresAuth: true, title: '修改昵称' }
  }, {
    path: '/user/inAudit',
    name: 'inAudit',
    component: InAudit,
    meta: { requiresAuth: true, title: '审核状态' }
  }, {
    path: '/accountListDay',
    name: 'accountListDay',
    component: AccountListDay,
    meta: { requiresAuth: true, title: '日账单' }
  }, {
    path: '/accountList',
    name: 'accountList',
    component: AccountList,
    meta: { requiresAuth: true, title: '我的账单' }
  }, {
    path: '/commissionList',
    name: 'commissionList',
    component: CommissionList,
    meta: { requiresAuth: true, title: '佣金明细' }
  }, {
    path: '/toCollection',
    name: 'toCollection',
    component: ToCollection,
    meta: { requiresAuth: true, title: '收藏司机' }
  }, {
    path: '/driverPage',
    name: 'driverPage',
    component: DriverPage,
    meta: { requiresAuth: true, title: '运力主页' }
  }, {
    path: '/offer',
    name: 'offer',
    component: Offer,
    meta: { requiresAuth: true, title: '报价' }
  }, {
    path: '/payOfInformation',
    name: 'payOfInformation',
    component: PayOfInformation,
    meta: { requiresAuth: true, title: '支付信息费' }
  }, {
    path: '/dispatchDriver',
    name: 'dispatchDriver',
    component: DispatchDriver,
    meta: { requiresAuth: true, title: '招标调度' }
  }, {
    path: '/shareTn',
    name: 'shareTn',
    component: ShareTn,
    meta: { requiresAuth: true, title: '分享有礼' }
  }, {
    path: '/selectService',
    name: 'selectService',
    component: SelectService,
    meta: { title: '选择服务类型' }
  }, {
    path: '/reportDriver',
    name: 'reportDriver',
    component: ReportDriver,
    meta: { requiresAuth: true, title: '上报司机' }
  }, {
    path: '/warning',
    name: 'warning',
    component: Warning,
    meta: { title: '账号身份错误' }
  }, {
    path: '*',
    component: NotFoundComponent
  }]
})

